package com.wollo.service.impl;

import com.wollo.domain.User;
import com.wollo.mapper.UserMapper;
import com.wollo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * //
 * //   █████▒█    ██  ▄████▄   ██ ▄█▀       ██████╗ ██╗   ██╗ ██████╗
 * // ▓██   ▒ ██  ▓██▒▒██▀ ▀█   ██▄█▒        ██╔══██╗██║   ██║██╔════╝
 * // ▒████ ░▓██  ▒██░▒▓█    ▄ ▓███▄░        ██████╔╝██║   ██║██║  ███╗
 * // ░▓█▒  ░▓▓█  ░██░▒▓▓▄ ▄██▒▓██ █▄        ██╔══██╗██║   ██║██║   ██║
 * // ░▒█░   ▒▒█████▓ ▒ ▓███▀ ░▒██▒ █▄       ██████╔╝╚██████╔╝╚██████╔╝
 * //  ▒ ░   ░▒▓▒ ▒ ▒ ░ ░▒ ▒  ░▒ ▒▒ ▓▒       ╚═════╝  ╚═════╝  ╚═════╝
 * //  ░     ░░▒░ ░ ░   ░  ▒   ░ ░▒ ▒░
 * //  ░ ░    ░░░ ░ ░ ░        ░ ░░ ░
 * //           ░     ░ ░      ░  ░
 * //                 ░
 *
 * @author Java song
 * @date 2024/9/16 下午7:14
 * @description
 **/
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Autowired
    private PasswordEncoder   passwordEncoder;
    //TODO 新增用户
    @Override
    public int addUser(User user) {
        //需要先查询用户id是否存在
        User userExist = userMapper.selectUserInfoByUserNameMapper(user.getUsername());
        if (userExist!=null){
            return 0;
        }
        //插入新用户数据并返回插入结果
        String encode = passwordEncoder.encode(user.getPwd());
        user.setPwd(encode);
        int i = userMapper.insertUser(user);
        return i;
    }

    ////TODO 更新个人信息
    @Override
    public int updateUser(User user) {
        int i = userMapper.updateTUser(user);
        return i;
    }
}
